﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Protell.Model.IRepository;
using Protell.Server.DAL.POCOS;

namespace Protell.Server.DAL.Repository
{
    public class CnfSettingRepository : IGnfSettingRepository
    {

        public void UpdateCnfSetting(Model.CnfSettingModel cnfSetting)
        {
            using (var entity = new db_SeguimientoProtocolo_r2Entities())
            {
                CNF_SETTINGS result = null;
                try
                {
                    result = (from o in entity.CNF_SETTINGS
                              where o.IdSetting == cnfSetting.IdSetting
                              select o).First();
                }
                catch (Exception ex)
                {
                    ;
                }

                if (result != null)
                {
                    result.Valor = cnfSetting.Valor;

                    entity.SaveChanges();
                }
            }
        }

        public Model.CnfSettingModel GetCnfSettingByID(long idSetting)
        {
            using (var entity = new db_SeguimientoProtocolo_r2Entities())
            {
                Model.CnfSettingModel setting = null;
                CNF_SETTINGS result = null;
                try
                {
                    result = (from o in entity.CNF_SETTINGS
                              where o.IdSetting == idSetting
                              select o).First();
                }
                catch (Exception ex)
                {
                    ;
                }

                if (result !=null)
                {
                    setting = new Model.CnfSettingModel()
                    { 
                        IdSetting = result.IdSetting,
                        SettingName = result.SettingName,
                        Valor = result.Valor,
                        IsActive = result.IsActive,
                        IsModified = result.IsModified,
                        LastModifiedDate = result.LastModifiedDate
                    };
                    
                }

                return setting;
            }
        }

        public Dictionary<string, string> GetResponseDictionary(string response)
        {
            throw new NotImplementedException();
        }

        public int GetDeserializeSettings(string response)
        {
            throw new NotImplementedException();
        }
    }
}
